#ifndef DRV_W5500_H
#define DRV_W5500_H

#include "spi.h"
//#include "TypeDefine.h"
#include "gpio.h"
#include <stdbool.h>

/*地址段*/
/*通用寄存器区寄存器偏移地址*/
#define W5500_MR_OFFSET             0x0000 
#define W5500_GAR0_OFFSET           0x0001 
#define W5500_GAR1_OFFSET           0x0002
#define W5500_GAR2_OFFSET           0x0003
#define W5500_GAR3_OFFSET           0x0004      
#define W5500_SUBR0_OFFSET          0x0005
#define W5500_SUBR1_OFFSET          0x0006
#define W5500_SUBR2_OFFSET          0x0007
#define W5500_SUBR3_OFFSET          0x0008
#define W5500_SHAR0_OFFSET          0x0009
#define W5500_SHAR1_OFFSET          0x000A
#define W5500_SHAR2_OFFSET          0x000B
#define W5500_SHAR3_OFFSET          0x000C
#define W5500_SHAR4_OFFSET          0x000D
#define W5500_SHAR5_OFFSET          0x000E   
#define W5500_SIPR0_OFFSET          0x000F
#define W5500_SIPR1_OFFSET          0x0010
#define W5500_SIPR2_OFFSET          0x0011
#define W5500_SIPR3_OFFSET          0x0012
#define W5500_INTLEVEL0_OFFSET      0x0013
#define W5500_INTLEVEL1_OFFSET      0x0014
#define W5500_IR_OFFSET             0x0015
#define W5500_IMR_OFFSET            0x0016
#define W5500_SIR_OFFSET            0x0017
#define W5500_SIMR_OFFSET           0x0018
#define W5500_RTR0_OFFSET           0x0019
#define W5500_RTR1_OFFSET           0x001A
#define W5500_RCR_OFFSET            0x001B
#define W5500_PTIMER_OFFSET         0x001C
#define W5500_PMAGIC_OFFSET         0x001D
#define W5500_PHAR0_OFFSET          0x001E
#define W5500_PHAR1_OFFSET          0x001F
#define W5500_PHAR2_OFFSET          0x0020
#define W5500_PHAR3_OFFSET          0x0021
#define W5500_PHAR4_OFFSET          0x0022
#define W5500_PHAR5_OFFSET          0x0023
#define W5500_PSID0_OFFSET          0x0024
#define W5500_PSID1_OFFSET          0x0025
#define W5500_PMRU0_OFFSET          0x0026
#define W5500_PMRU1_OFFSET          0x0027
#define W5500_UIPR0_OFFSET          0x0028
#define W5500_UIPR1_OFFSET          0x0029
#define W5500_UIPR2_OFFSET          0x002A
#define W5500_UIPR3_OFFSET          0x002B
#define W5500_UPORTR0_OFFSET        0x002C
#define W5500_UPORTR1_OFFSET        0x002D
#define W5500_PHYCFGR_OFFSET        0x002E
#define W5500_VERSIONR_OFFSET       0x0039

/*Socket寄存器*/
#define W5500_Sn_MR_OFFSET          0x0000
#define W5500_Sn_CR_OFFSET          0x0001
#define W5500_Sn_IR_OFFSET          0x0002
#define W5500_Sn_SR_OFFSET          0x0003
#define W5500_Sn_PORT0_OFFSET       0x0004
#define W5500_Sn_PORT1_OFFSET       0x0005
#define W5500_Sn_DHAR0_OFFSET       0x0006
#define W5500_Sn_DHAR1_OFFSET       0x0007
#define W5500_Sn_DHAR2_OFFSET       0x0008
#define W5500_Sn_DHAR3_OFFSET       0x0009
#define W5500_Sn_DHAR4_OFFSET       0x000A
#define W5500_Sn_DHAR5_OFFSET       0x000B
#define W5500_Sn_DIPR0_OFFSET       0x000C
#define W5500_Sn_DIPR1_OFFSET       0x000D
#define W5500_Sn_DIPR2_OFFSET       0x000E
#define W5500_Sn_DIPR3_OFFSET       0x000F
#define W5500_Sn_DPORT0_OFFSET      0x0010
#define W5500_Sn_DPORT1_OFFSET      0x0011
#define W5500_Sn_MSSR0_OFFSET       0x0012
#define W5500_Sn_MSSR1_OFFSET       0x0013
#define W5500_Sn_TOS_OFFSET         0x0015
#define W5500_Sn_TTL_OFFSET         0x0016
#define W5500_Sn_RXBUF_SIZE_OFFSET  0x001E
#define W5500_Sn_TXBUF_SIZE_OFFSET  0x001F
#define W5500_Sn_TX_FSR0_OFFSET     0x0020
#define W5500_Sn_TX_FSR1_OFFSET     0x0021
#define W5500_Sn_TX_RD0_OFFSET      0x0022
#define W5500_Sn_TX_RD1_OFFSET      0x0023
#define W5500_Sn_TX_WR0_OFFSET      0x0024
#define W5500_Sn_TX_WR1_OFFSET      0x0025
#define W5500_Sn_RX_RSR0_OFFSET     0x0026
#define W5500_Sn_RX_RSR1_OFFSET     0x0027
#define W5500_Sn_RX_RD0_OFFSET      0x0028
#define W5500_Sn_RX_RD1_OFFSET      0x0029
#define W5500_Sn_RX_WR0_OFFSET      0x002A
#define W5500_Sn_RX_WR1_OFFSET      0x002B
#define W5500_Sn_IMR_OFFSET         0x002C
#define W5500_Sn_FRAG0_OFFSET       0x002D
#define W5500_Sn_FRAG1_OFFSET       0x002E
#define W5500_Sn_KPALVTR_OFFSET     0x002F


/*控制段*/
/*BSB[7:3]*/
#define W5500_SELECT_COMM_REG        0x00  /*选择通用寄存器*/

#define W5500_SELECT_SOCKET0_REG     0x01  /*选择Socket0寄存器*/
#define W5500_SELECT_SOCKET0_TXBUFF  0x02  /*选择Socket0发送缓存*/
#define W5500_SELECT_SOCKET0_RXBUFF  0x03  /*选择Socket0接收缓存*/
                                         
#define W5500_SELECT_SOCKET1_REG     0x05  /*选择Socket1寄存器*/
#define W5500_SELECT_SOCKET1_TXBUFF  0x06  /*选择Socket1发送缓存*/
#define W5500_SELECT_SOCKET1_RXBUFF  0x07  /*选择Socket1接收缓存*/
                                         
#define W5500_SELECT_SOCKET2_REG     0x09  /*选择Socket2寄存器*/
#define W5500_SELECT_SOCKET2_TXBUFF  0x0A  /*选择Socket2发送缓存*/
#define W5500_SELECT_SOCKET2_RXBUFF  0x0B  /*选择Socket2接收缓存*/
                                         
#define W5500_SELECT_SOCKET3_REG     0x0D  /*选择Socket3寄存器*/
#define W5500_SELECT_SOCKET3_TXBUFF  0x0E  /*选择Socket3发送缓存*/
#define W5500_SELECT_SOCKET3_RXBUFF  0x0F  /*选择Socket3接收缓存*/
                                         
#define W5500_SELECT_SOCKET4_REG     0x11  /*选择Socket4寄存器*/
#define W5500_SELECT_SOCKET4_TXBUFF  0x12  /*选择Socket4发送缓存*/
#define W5500_SELECT_SOCKET4_RXBUFF  0x13  /*选择Socket4接收缓存*/
                                         
#define W5500_SELECT_SOCKET5_REG     0x15  /*选择Socket5寄存器*/
#define W5500_SELECT_SOCKET5_TXBUFF  0x16  /*选择Socket5发送缓存*/
#define W5500_SELECT_SOCKET5_RXBUFF  0x17  /*选择Socket5接收缓存*/

//用于httpserver请求专用通道,防止混用干扰                                    
// #define W5500_SELECT_SOCKET6_REG     0x19  /*选择Socket6寄存器*/
// #define W5500_SELECT_SOCKET6_TXBUFF  0x1A  /*选择Socket6发送缓存*/
// #define W5500_SELECT_SOCKET6_RXBUFF  0x1B  /*选择Socket6接收缓存*/
                                         
// #define W5500_SELECT_SOCKET7_REG     0x1D  /*选择Socket7寄存器*/
// #define W5500_SELECT_SOCKET7_TXBUFF  0x1E  /*选择Socket7发送缓存*/
// #define W5500_SELECT_SOCKET7_RXBUFF  0x1F  /*选择Socket7接收缓存*/

#define IS_W5500_SOCKET_REG(x) (((x) == W5500_SELECT_SOCKET0_REG) || ((x) == W5500_SELECT_SOCKET1_REG) || \
                                ((x) == W5500_SELECT_SOCKET2_REG) || ((x) == W5500_SELECT_SOCKET3_REG) || \
                                ((x) == W5500_SELECT_SOCKET4_REG) || ((x) == W5500_SELECT_SOCKET5_REG))
                                //|| \
                                //((x) == W5500_SELECT_SOCKET6_REG) || ((x) == W5500_SELECT_SOCKET7_REG))

/*OM[1:0]*/
#define W5500_VDM                (0x00)  /*可变数据长度模式*/
#define W5500_FDM1               (0x01)  /*固定数据长度，N=1*/
#define W5500_FDM2               (0x02)  /*固定数据长度，N=2*/
#define W5500_FDM4               (0x03)  /*固定数据长度，N=4*/

/*PHYCGF(0x2E)*/
#define W5500_PHYCFGR_RST        (0x01 << 7)  /*重启*/
#define W5500_PHYCFGR_OPMD       (0x01 << 6)  /*配置PHY工作模式*/
#define W5500_PHYCFGR_OPMDC      (0x07 << 3)  /*工作模式配置位*/
#define W5500_PHYCFGR_DPX        (0x01 << 2)  /*双工工作状态*/
#define W5500_PHYCFGR_SPD        (0x01 << 1)  /*速度状态*/
#define W5500_PHYCFGR_LNK        (0x01 << 0)  /*连接状态，只读*/

/*Sn_MR(0x00)*/
#define W5500_Sn_MR_DACK         (0x00 << 5)
#define W5500_Sn_MR_NDACK        (0x01 << 5)
#define W5500_Sn_MR_CLOSE        (0x00 << 0)
#define W5500_Sn_MR_TCP          (0x01 << 0)
#define W5500_Sn_MR_UDP          (0x02 << 0)
#define W5500_Sn_MR_MACRAW       (0x03 << 0)

#define IS_W5500_MR_PROTOCOL(x)  (((x) == W5500_Sn_MR_CLOSE) || ((x) == W5500_Sn_MR_TCP) || \
                                  ((x) == W5500_Sn_MR_UDP) || ((x) == W5500_Sn_MR_MACRAW))

/*Sn_CR(0x01)*/
#define W5500_Sn_CR_OPEN         (0x01)  /*打开Socket*/
#define W5500_Sn_CR_LISTEN       (0x02)  /*Socket配置为服务器模式，等待TCP客户端连接请求*/
#define W5500_Sn_CR_CONNECT      (0x04)  /*Socket配置为客户端模式，向TCP服务器发送连接请求*/
#define W5500_Sn_CR_DISCON       (0x08)  /*断开TCP连接*/
#define W5500_Sn_CR_CLOSE        (0x10)  /*关闭Socket*/
#define W5500_Sn_CR_SEND         (0x20)  /*Socket发送缓存数据*/
#define W5500_Sn_CR_SEND_MAC     (0x21)  /*Socket发送缓存数据附带MAC地址*/
#define W5500_Sn_CR_SEND_KEEP    (0x22)  /*发送心跳包*/
#define W5500_Sn_CR_RECV         (0x40)  /*更新接收缓存的指针，接收数据*/

/*SN_IR(0x02)*/   
#define W5500_Sn_IR_SENDOF       (0x01 << 4)  /*Send命令发生完成*/
#define W5500_Sn_IR_TIMEOUT      (0x01 << 3)  /*ARP或TCP超时被触发*/
#define W5500_Sn_IR_RECV         (0x01 << 2)  /*接收到数据*/
#define W5500_Sn_IR_DISCON       (0x01 << 1)  /*接收到FIN或FIN/ACK*/
#define W5500_Sn_IR_CON          (0x01 << 0)  /*建立连接，且Sn_SR变为SOCK_ESTABLISHED状态*/

/*Sn_SR(0x03)*/
#define W5500_Sn_SR_CLOSED       (0x00)  /*Socket处于关闭状态，资源被释放*/
#define W5500_Sn_SR_INIT         (0x13)  /*Socket端口打开并处于TCP工作模式*/
#define W5500_Sn_SR_LISTEN       (0x14)  /*Socket工作在TCP服务模式下*/
#define W5500_Sn_SR_ESTABLISHED  (0x17)  /*Socket建立了连接*/
#define W5500_Sn_SR_CLOSE_WAIT   (0x1C)  /*Socket接收到关闭连接请求*/
#define W5500_Sn_SR_UDP          (0x22)  /*Socket处于UDP模式下*/
#define W5500_Sn_SR_MACRAW       (0x42)  /*Socket处于MACRAW模式下*/
#define W5500_Sn_SR_SYNSENT      (0x15)  /*Socket已经发送连接请求到对方*/
#define W5500_Sn_SR_SYNRECV      (0x16)  /*Socket接收到对方发送的连接请求*/
#define W5500_Sn_SR_FIN_WAIT     (0x18)  /*Socket关闭过程状态*/
#define W5500_Sn_SR_COLSING      (0x1A)  /*Socket关闭过程状态*/
#define W5500_Sn_SR_TIME_WAIT    (0x1B)  /*Socket关闭过程状态*/
#define W5500_Sn_SR_LAST_ACK     (0x1D)  /*Socket等待断开连接请求做出回应*/

/*W5500_Sn_RXBUF_SIZE(0x1E)*/
#define W5500_Sn_RXBUF_0KB       (0)
#define W5500_Sn_RXBUF_1KB       (1)
#define W5500_Sn_RXBUF_2KB       (2)
#define W5500_Sn_RXBUF_4KB       (4)
#define W5500_Sn_RXBUF_8KB       (8)
#define W5500_Sn_RXBUF_16KB      (16)
   
/*W5500_Sn_TXBUF_SIZE(0x1F)*/   
#define W5500_Sn_TXBUF_0KB       (0)
#define W5500_Sn_TXBUF_1KB       (1)
#define W5500_Sn_TXBUF_2KB       (2)
#define W5500_Sn_TXBUF_4KB       (4)
#define W5500_Sn_TXBUF_8KB       (8)
#define W5500_Sn_TXBUF_16KB      (16)


/*通用寄存器*/
#define W5500_MR(x)                    ((x) << 8)

/*Socket寄存器*/
#define W5500_Sn_MR(SOCKET)            ((W5500_Sn_MR_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_CR(SOCKET)            ((W5500_Sn_CR_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_IR(SOCKET)            ((W5500_Sn_IR_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_SR(SOCKET)            ((W5500_Sn_SR_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_PORT0(SOCKET)         ((W5500_Sn_PORT0_OFFSET << 8) | (SOCKET) << 3)
#define W5500_Sn_RXBUF_SIZE(SOCKET)    ((W5500_Sn_RXBUF_SIZE_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_TXBUF_SIZE(SOCKET)    ((W5500_Sn_TXBUF_SIZE_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_PORT1(SOCKET)         ((W5500_Sn_PORT1_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_TX_FSR0(SOCKET)       ((W5500_Sn_TX_FSR0_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_TX_FSR1(SOCKET)       ((W5500_Sn_TX_FSR1_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_TX_WR0(SOCKET)        ((W5500_Sn_TX_WR0_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_TX_WR1(SOCKET)        ((W5500_Sn_TX_WR1_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_RX_RSR0(SOCKET)       ((W5500_Sn_RX_RSR0_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_RX_RSR1(SOCKET)       ((W5500_Sn_RX_RSR1_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_RX_RD0(SOCKET)        ((W5500_Sn_RX_RD0_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_RX_RD1(SOCKET)        ((W5500_Sn_RX_RD1_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_Rx_WR0(SOCKET)        ((W5500_Sn_RX_WR0_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_Rx_WR1(SOCKET)        ((W5500_Sn_RX_WR1_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_KPALVTR(SOCKET)       ((W5500_Sn_KPALVTR_OFFSET << 8) | ((SOCKET) << 3))
#define W5500_Sn_TX_BUFF(ADDR, SOCKET) ((ADDR << 8) | ((SOCKET + 1) << 3))
#define W5500_Sn_RX_BUFF(ADDR, SOCKET) ((ADDR << 8) | ((SOCKET + 2) << 3))

#define W5500_Sn_DIPR0(SOCKET)         ((W5500_Sn_DIPR0_OFFSET << 8) | (SOCKET) << 3)   
#define W5500_Sn_DPORT0(SOCKET)        ((W5500_Sn_DPORT0_OFFSET << 8) | (SOCKET) << 3)


/*RWB[2]*/
#define W5500_R (0x00 << 2) /*读*/
#define W5500_W (0x01 << 2) /*写*/

/*网络配置结构体*/
typedef struct
{
    uint8_t  auch_GA[4];       /*网关IP地址*/
    uint8_t  auch_SUB[4];      /*子网掩码*/
    uint8_t  auch_SHA[6];      /*源MAC地址*/
    uint8_t  auch_SIP[4];      /*源IP地址*/
    uint16_t uin_RTR;          /*重试超时时间*/
    uint8_t  uch_RCR;          /*重试次数*/
	  uint8_t  auch_DNS[4];      /* DNS服务器地址 */
}NetCfg_TypeDef;

/*Socket接收发送缓存配置*/
typedef struct
{
    uint16_t  uin_Port;          /*Socket端口号*/
    uint16_t *puin_RxSize;       /*Socket接收字节数指针*/
    uint16_t *puin_TxSize;       /*Socket发送字节数指针*/
    uint8_t  *puch_RxBuff;       /*Socket接收缓存指针*/
    uint8_t  *puch_TxBuff;       /*Socket发送缓存指针*/
    uint8_t   uch_RxBuffSize;    /*Socket接收缓存大小设置*/
    uint8_t   uch_TxBuffSize;    /*Socket发送缓存大小设置*/
    uint8_t   uch_HaveRecvFlag;  /*Socket有接收数据*/
}Socket_TypeDef;

/*远端网络配置结构体
* 客户端存储所连接服务器ip:port
* 服务端存储所连接客户端的ip:port
*/
typedef struct
{
    uint8_t auch_IP[4];  /*Socket连接远程IP地址*/
    uint16_t uin_Port;   /*Socket端口号*/
}RemotNetCfg_TypeDef;

typedef struct
{
    SPI_HandleTypeDef  *pst_hspi;        /*SPI接口*/
    GPIO_TypeDef       *pst_CS_GPIO;     /*SPI CS GPIO*/
    uint32_t            ul_CS_PIN;       /*SPI CS PIN*/
    GPIO_TypeDef       *pst_RST_GPIO;    /*RST GPIO*/
    uint32_t            ul_RST_PIN;      /*RST PIN*/
     
    uint8_t             uch_PHYConnect;  /*网线连接状态，0：未连接，1：已连接*/
    NetCfg_TypeDef      st_CfgMsg;       /*网络配置信息*/
    Socket_TypeDef      st_Socket[8];    /*Socket参数*/
    RemotNetCfg_TypeDef ast_RemotCfg[8]; /*远端网络参数配置*/
}W5500_TypeDef;


typedef struct {
    uint8_t socket_num;  // Socket编号
    void (*RxCplCallback)(void); // 数据接收回调
} W5500_Socket_t;


extern W5500_TypeDef gst_W5500_Dev;
extern uint16_t Local_Port;
extern uint8_t REMOTE_IP[4];
extern uint16_t REMOTE_Port;

#ifdef __cplusplus
extern "C" {
#endif

/*初始化函数*/
void Drv_W5500_Init(W5500_TypeDef *pst_EthStruct);
void Drv_W5500_Reset(W5500_TypeDef *pst_EthStruct);

/*应用函数*/
void Drv_TCPServer(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
void Drv_TCPClient(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, const uint8_t *puch_ServerIP, uint16_t uin_ServerPort);
uint8_t Drv_W5500_Connect(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, const uint8_t *puch_ServerIP, uint16_t uin_ServerPort);
void Drv_W5500_Listen(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
void Drv_W5500_CloseSocket(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
void Drv_W5500_Receive_UDP(W5500_TypeDef *pst_W5500_Dev, uint8_t uch_Socket);
void Drv_W5500_PHYCheck(W5500_TypeDef *pst_EthStruct);
void Drv_W5500_TCPRecv(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_TCPSend(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_TCPSendEx(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint8_t *pData, uint16_t len);
uint8_t Drv_W5500_SendDummy(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
void Drv_W5500_ClearRecvFlag(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_GetRecvFlag(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_SocketCfg(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint8_t uch_Protocol, uint8_t Flag);
void Drv_W5500_KeepAlive(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);

void Drv_W5500_SetSn_DIPR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, const uint8_t *puch_ServerIP);
void Drv_W5500_SetSn_DPORT(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint16_t uin_ServerPort);
//void Drv_W5500_SetSn_TX_FSR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint16_t uin_Data);       
//void Drv_W5500_WriteMem(W5500_TypeDef *pst_EthStruct, uint32_t ul_Addr, uint8_t *puch_TxData, uint8_t uch_Size);


/*通用寄存器函数*/
void Drv_W5500_SetSHAR(W5500_TypeDef *pst_EthStruct);
void Drv_W5500_SetGAR(W5500_TypeDef *pst_EthStruct);
void Drv_W5500_SetSUBR(W5500_TypeDef *pst_EthStruct);
void Drv_W5500_SetSIPR(W5500_TypeDef *pst_EthStruct);
void Drv_W5500_SetRTR(W5500_TypeDef *pst_EthStruct);
void Drv_W5500_SetRCR(W5500_TypeDef *pst_EthStruct);

void Drv_W5500_GetSHAR(W5500_TypeDef *pst_EthStruct, uint8_t *puch_Data);
void Drv_W5500_GetGAR(W5500_TypeDef *pst_EthStruct, uint8_t *puch_Data);
void Drv_W5500_GetSUBR(W5500_TypeDef *pst_EthStruct, uint8_t *puch_Data);
void Drv_W5500_GetSIPR(W5500_TypeDef *pst_EthStruct, uint8_t *puch_Data);
void Drv_W5500_GetPHY(W5500_TypeDef *pst_EthStruct, uint8_t *puch_Data);


/*Socket寄存器函数*/
void Drv_W5500_SetSn_MR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint8_t uch_Data);
void Drv_W5500_SetSn_CR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint8_t uch_Data);
void Drv_W5500_SetSn_IR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint8_t uch_Data);
void Drv_W5500_SetSn_SR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint8_t uch_Data);
void Drv_W5500_SetSn_Port(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint16_t uin_Data);
void Drv_W5500_SetSn_TX_WR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint16_t uin_Data);
void Drv_W5500_SetSn_Rx_RD(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint16_t uin_Data);
void Drv_W5500_SetSn_KPALVTR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket, uint8_t uch_Data);

uint8_t Drv_W5500_GetSn_MR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_GetSn_CR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_GetSn_IR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_GetSn_SR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_MyGetSn_SR(uint8_t uch_Socket);
uint16_t Drv_W5500_GetSn_Port(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint16_t Drv_W5500_GetSn_TX_FSR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint16_t Drv_W5500_GetSn_TX_WR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint16_t Drv_W5500_GetSn_RX_RSR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint16_t Drv_W5500_GetSn_Rx_RD(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint16_t Drv_W5500_GetSn_Rx_WR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);
uint8_t Drv_W5500_GettSn_KPALVTR(W5500_TypeDef *pst_EthStruct, uint8_t uch_Socket);

/*寄存器读写驱动*/
void Drv_W5500_ReadReg(W5500_TypeDef *pst_EthStruct, uint32_t ul_Addr, uint8_t *puch_RxData);
void Drv_W5500_WriteReg(W5500_TypeDef *pst_EthStruct, uint32_t ul_Addr, uint8_t uch_TxData);
void Drv_W5500_ReadMem(W5500_TypeDef *pst_EthStruct, uint32_t ul_Addr, uint8_t *puch_RxData, uint16_t uin_Size);
void Drv_W5500_WriteMem(W5500_TypeDef *pst_EthStruct, uint32_t ul_Addr, uint8_t *puch_TxData, uint16_t uin_Size);


uint8_t w5500_read_byte(void);
void w5500_write_byte(uint8_t byte);


#ifdef __cplusplus
}
#endif


#endif
